<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="favicon.ico"> <link href="./src/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="./src/css/font-awesome.css?v=4.4.0" rel="stylesheet">
        <link href="./src/css/plugins/iCheck/custom.css" rel="stylesheet">
        <link href="./src/css/animate.css" rel="stylesheet">
        <link href="./src/css/style.css?v=4.1.0" rel="stylesheet">
        <link href="./src/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
        <script type="text/javascript" src="src/js/jquery.min.js"></script>
        <script src="./src/js/jquery.min.js?v=2.1.4"></script>
        <script src="./src/js/bootstrap.min.js?v=3.3.6"></script>
        <script src="./src/js/content.js?v=1.0.0"></script>
        <script src="./src/js/plugins/sweetalert/sweetalert.min.js"></script>
        <script>
            $(function() {
                $('.tbody').click(function() {
                    if ($(this).hasClass('main_in_tr_content_cur')) {
                        var dos = 1;
                    }
                    $('.tbody').removeClass('main_in_tr_content_cur');
                    if (dos != 1) {
                        $(this).addClass('main_in_tr_content_cur');
                    }
                });

                $('#baocun').click(function() {
                    var city_name = $("#name").val();
                    var city_code = $("#code").val();
                    var province_id = $("#province_id").val();
                    var is_yard = $("#is_yard").val();
                    $.post("./?m=area&a=docityadd", {city_name: city_name, city_code: city_code, province_id: province_id, is_yard: is_yard}, function(result) {
                        if (result > 0) {
                            swal({
                                title: "提交数据成功",
                                text: "THIS IS OK。"
                            }, function() {
                                location.href = "./?m=area&a=citylist";
                            });
                        }
                        ;
                    });
                });
                
                $("#update_val").click(function(){
                    var province_id = $(".main_in_tr_content_cur").find('.province_id').html();
                    var name = $(".main_in_tr_content_cur").find('td').eq(2).html();
                    var code = $(".main_in_tr_content_cur").find('td').eq(3).html();
                    var is_yard = $(".main_in_tr_content_cur").find('.is_yard').html();
                    if(name == undefined){
                        swal({
                                title: "请选择列表",
                                text: "THIS IS ERROR。"
                            });
                        return false;
                    }
                    $("#update_name").val(name);
                    $("#update_code").val(code);
                    $("#update_id").find('option[value='+province_id+']').prop("selected",true); 
                    $("#update_is_yard").find('option[value='+is_yard+']').prop("selected",true); 
                });
                
                $('#do_update').click(function() {
                    var city_name = $("#update_name").val();
                    var city_code = $("#update_code").val();
                    var province_id = $("#update_id").val();
                    var is_yard = $("#update_is_yard").val();
                    var id = $(".main_in_tr_content_cur").find('td').eq(0).html();
                    $.post("./?m=area&a=docityupdate", {city_name: city_name, city_code: city_code,province_id: province_id, is_yard: is_yard,id:id}, function(result) {
                        if (result > 0) {
                            swal({
                                title: "提交数据成功",
                                text: "THIS IS OK。"
                            }, function() {
                                location.href = "./?m=area&a=citylist";
                            });
                        } else {
                            swal({
                                title: "提交数据失败",
                                text: "THIS IS ERROR。"
                            }, function() {
                                    location.href = "./?m=area&a=citylist";
                            });
                        }
                        ;
                    });
                });
                
                $("#do_no").click(function() {
                    var id = $(".main_in_tr_content_cur").find('td').eq(0).html();
                    if (id != undefined) {
                        $.post("./?m=area&a=docitydel", {id: id,type:2 }, function(result) {
                            if (result > 0) {
                                swal({
                                    title: "数据休眠成功",
                                    text: "THIS IS OK。"
                                }, function() {
                                    location.href = "./?m=area&a=citylist";
                                });
                            } else {
                                swal({
                                    title: "数据休眠失败",
                                    text: "THIS IS ERROR。"
                                }, function() {
                                    location.href = "./?m=area&a=citylist";
                                });
                            }
                            ;
                        });
                    }else{
                            swal({
                                title: "请选择列表",
                                text: "THIS IS ERROR。"
                            });
                            return false;
                    } 

                });
                
                $("#do_yes").click(function() {
                    var id = $(".main_in_tr_content_cur").find('td').eq(0).html();
                    if (id != undefined) {
                        $.post("./?m=area&a=docitydel", {id: id,type:1 }, function(result) {
                            if (result > 0) {
                                swal({
                                    title: "数据激活成功",
                                    text: "THIS IS OK。"
                                }, function() {
                                    location.href = "./?m=area&a=citylist";
                                });
                            } else {
                                swal({
                                    title: "数据激活失败",
                                    text: "THIS IS ERROR。"
                                }, function() {
                                    location.href = "./?m=area&a=citylist";
                                });
                            }
                            ;
                        });
                    }else{
                            swal({
                                title: "请选择列表",
                                text: "THIS IS ERROR。"
                            });
                            return false;
                    } 

                });
                
                $("#delete").click(function() {
                    var id = $(".main_in_tr_content_cur").find('td').eq(0).html();
                    if (id != undefined) {
                        $.post("./?m=area&a=docitydel", {id: id,type:0 }, function(result) {
                            if (result > 0) {
                                swal({
                                    title: "数据删除成功",
                                    text: "THIS IS OK。"
                                }, function() {
                                    location.href = "./?m=area&a=citylist";
                                });
                            } else {
                                swal({
                                    title: "数据删除失败",
                                    text: "THIS IS ERROR。"
                                }, function() {
                                    location.href = "./?m=area&a=citylist";
                                });
                            }
                            ;
                        });
                    }else{
                            swal({
                                title: "请选择列表",
                                text: "THIS IS ERROR。"
                            });
                            return false;
                    } 

                });
                
                
            });
        </script>
    </head>
    <body>
        <div class="ibox-content">
            <form class="form-horizontal">
                <input type="hidden" name="m" value="area" />
                <input type="hidden" name="a" value="citylist" />
                <div class="form-group">
                    <label class="col-sm-2 control-label w100">地区名称：</label>
                    <div class="col-sm-2">
                        <select class="form-control m-b" name="province_id" style="padding-top:2px;">
                            <option value="">全部</option>
                            <?php foreach($this->province as $k => $v){ ?>
                            <option <?php echo $this->province_id == $v['id'] ? 'selected': ''; ?> value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label w100">地点名称：</label>
                    <div class="col-sm-2">
                        <select class="form-control m-b" name="id" style="padding-top:2px;">
                            <option value="">全部</option>
                            <?php foreach($this->data as $k => $v){ ?>
                            <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label w100">当前状态：</label>
                    <div class="col-sm-2">
                        <select class="form-control m-b" id="search_type" name="search_type" style="padding-top:2px;">
                            <option value="3">全部</option>
                            <option <?php echo $this->status == 1?'selected':''; ?> value="1">激活</option>
                            <option <?php echo $this->status == 2?'selected':''; ?> value="2">休眠</option>
                        </select>
                    </div>
                    <div class="col-sm-1">
                        <button class="btn btn-sm btn-info" type="submit">搜索</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="row">
            <div class="ibox float-e-margins" style="width:98%;margin-left:1%;">
                <div class="ibox-title">
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#myModal5"><span class="bold">新增</span></button>  
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#update" id="update_val"><span class="bold">修改</span></button> 
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#delete" id="do_no" ><span class="bold">休眠</span></button>
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#delete" id="do_yes" ><span class="bold">激活</span></button>    
                    <button class="btn btn-success " style="margin-top:-10px;" type="button" data-toggle="modal" data-target="#delete" id="delete" ><span class="bold">删除</span></button>  
                </div>
                <div class="ibox-content">

                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>序号</th>
                                <th>所属地区</th>
                                <th>地点名称</th>
                                <th>地点编号</th>
                                <th>是否堆场</th>
                                <th>当前状态</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $qq=1; foreach ($this->data as $k => $v) { ?>
                                <tr class="tbody">
                                    <td style="display: none;"><?php echo $v['id'] ?></td>
                                    <td><?php echo $qq; ?></td>
                                    <td><?php echo $v['province_name'] ?></th>
                                    <td><?php echo $v['name'] ?></td>
                                    <td><?php echo $v['code'] ?></td>
                                    <td><?php echo $v['is_yard'] == 1 ? '是': '否'; ?></td>
                                    <td><?php echo $v['status'] == 1 ? '激活': '休眠'; ?></td>
                                    <td style="display: none" class="province_id"><?php echo $v['province_id'] ?></th>
                                    <td style="display: none" class="is_yard"><?php echo $v['is_yard'] ?></th>
                                </tr>
                            <?php $qq++;} ?>
                        </tbody>
                    </table>

                </div>
            </div>
        </div>
                   <div class="admin-table-page" style="margin-left:20px;">
            <div id="page" class="page">
                <?php echo $this->paging; ?>
            </div>
        </div>
        <div class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">地点信息资料</h4>
                    </div>
                    <div class="modal-body">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>地点新增</h5>
                            </div>
                            <div class="ibox-content">
                                <form role="form" class="form-horizontal">
                                    <input type="hidden" name="m" value="acl" />
                                    <input type="hidden" name="a" value="" />
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">地点名称：</label>
                                        <div class="col-sm-4">
                                            <input class="form-control m-b" id="name" type="text" />
                                        </div>
                                        <label class="col-sm-2 control-label">地点编号：</label>
                                        <div class="col-sm-4">
                                            <input class="form-control m-b" id="code" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">所属地区：</label>
                                        <div class="col-sm-4">
                                            <select class="form-control m-b" name="account" id="province_id" style="padding-top:2px;">
                                                <?php foreach ($this->province as $k => $v) { ?>
                                                    <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                        <label class="col-sm-2 control-label">是否堆场：</label>
                                        <div class="col-sm-4">
                                            <select class="form-control m-b" name="account" id="is_yard" style="padding-top:2px;">
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" id="gb" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="baocun">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <!----修改---->
        <div class="modal inmodal fade" id="update" tabindex="-1" role="dialog"  aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">地点信息资料</h4>
                    </div>
                    <div class="modal-body">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>地点修改</h5>
                            </div>
                            <div class="ibox-content">
                                <form role="form" class="form-horizontal">
                                    <input type="hidden" name="m" value="area" />
                                    <input type="hidden" name="a" value="" />
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">地点名称：</label>
                                        <div class="col-sm-4">
                                            <input class="form-control m-b" id="update_name" type="text" />
                                        </div>
                                        <label class="col-sm-2 control-label">地点编号：</label>
                                        <div class="col-sm-4">
                                            <input class="form-control m-b" id="update_code" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">所属地区：</label>
                                        <div class="col-sm-4">
                                            <select class="form-control m-b" name="account" id="update_id" style="padding-top:2px;">
                                                <?php foreach ($this->province as $k => $v) { ?>
                                                    <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                        <label class="col-sm-2 control-label">是否堆场：</label>
                                        <div class="col-sm-4">
                                            <select class="form-control m-b" name="account" id="update_is_yard" style="padding-top:2px;">
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" id="gb" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="do_update">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="outside_pull"></div>
    </body>
</html>
